package com.hnevc.charpt2;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;

/**
 * 1.读取项目目录中的data.txt文件，获取所有的同学姓名，保存到字符串s中
 * 2.将s中的数据解析，并存放到数组中String[] names中
 * 3.产生随机数，完成点名。
 * @author Administrator
 *
 */
public class CallName {
	public static void showMenu(){
		System.out.println("---------点名----------");
		System.out.println("0----退出");
		System.out.println("1----点名");
		System.out.println("----------------------");
	}
	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		//1获取数据到字符串中
		File file = new File("data.txt");
		Scanner scanner = new Scanner(file);
		String s = scanner.nextLine();
		showMenu();
		//2 拆分字符串，保存到数组中
		String[] names = s.split("-");
		
		Scanner sc = new Scanner(System.in);
		int item = sc.nextInt();
		while(item!=0){
			
			//3 点名
			String name = getRandomName(names);
			System.out.println(name);
			showMenu();
			item = sc.nextInt();
		}
		
	}

	
	private static String getRandomName(String[] names) {
		// TODO Auto-generated method stub
		
			Random random = new Random();
			int index = random.nextInt(names.length);
			return names[index];
		
		
	}

}
